package com.qidian.mes.cal.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.cal.mapper.CalTeamMapper;
import com.qidian.mes.cal.service.CalTeamService;
import com.qidian.mes.pojo.CalTeam;
import com.qidian.mes.pojo.Dict;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author zhangYu
 * @Company 起点编程
 * @Time 2023/10/26 15:06
 * @Description
 */
@Service
public class CalTeamServiceImpl implements CalTeamService {

    @Autowired
    private CalTeamMapper calTeamMapper;

    @Override
    public MESResult get(Long teamId) {
        return MESResult.ok(calTeamMapper.get(teamId));
    }
    @Override
    public MESResult list(int page, int limit, CalTeam calTeam) {
        // 开启分页 在当前线程中执行下一条SQL的时候就会进行分页。
        PageHelper.startPage(page,limit);
        List<CalTeam> list = calTeamMapper.list(calTeam);
        // 组织一个分页对象。（页码，每页大小，最大页码，数据，总条数）
        PageInfo<CalTeam> pageInfo = new PageInfo<>(list);
        return MESResult.ok(pageInfo);
    }

    @Override
    public MESResult update(CalTeam calTeam) {
        if (calTeam.getTeamName() != null) {
            MESResult.updateIsOk(calTeamMapper.updateTeamName(calTeam.getTeamName()));
        } else if (calTeam.getTeamCode() != null) {
            MESResult.updateIsOk(calTeamMapper.updateTeamCode(calTeam.getTeamCode()));
        } else if (calTeam.getCalendarType() != null) {
            MESResult.updateIsOk(calTeamMapper.updateCalendarType(calTeam.getCalendarType()));
        } else if (calTeam.getRemark() != null) {
            MESResult.updateIsOk(calTeamMapper.updateRemark(calTeam.getRemark()));
        }
        return MESResult.fail();
    }

    @Override
    public MESResult save(CalTeam calTeam) {
        if (calTeamMapper.save(calTeam)>0) {
            MESResult.ok();
        }
        return MESResult.fail();
    }

    @Override
    public MESResult deleteByCalTeamId(Long teamId) {
        if (calTeamMapper.deleteByTeamId(teamId) >0) {
            return MESResult.ok();
        }
        return MESResult.fail();
    }

    @Override
    public MESResult deleteByCalTeamCode(String teamCode) {
        if (calTeamMapper.deleteByTeamCode(teamCode) >0) {
            return MESResult.ok();
        }
        return MESResult.fail();
    }

}
